#!/bin/bash

# The arguments to the script are
# $1: the name of the relation to be loaded
# $2: the number of fragments the generator produces
#     has to be the same as in relationname.m4
# $3: the option to dbgen that produced the desired relation
#     the option for lineitem is L
# $4: the scale factor (1 is 1GB)

REL_NAME=$1
NUM_FRAGMENTS=$2
TPCH_OPTION=$3

killall -9 dbgen

# echo "Building the bulk loader"
./GenerateBulkLoader.sh ${REL_NAME}1T.m4

echo "Create the named pipes to talk to dbgen."
for i in `seq $2`; do
    rm -f $REL_NAME.tbl.$i
    mkfifo $REL_NAME.tbl.$i
done

echo "Starting the TPCH data generator."
./dbgen -C $NUM_FRAGMENTS -s 1000 -T $TPCH_OPTION > TPCH-OUT&
echo "./dbgen -C $NUM_FRAGMENTS -s 1000 -T $TPCH_OPTION"

echo "Now you can start the bulk loader."
#./bulkLoader > OUTPUT &
